from typing import List

from sqlalchemy.orm import Session

from app.models import TaskClassificationLibrary
from app.schemas.task_classification_library import TaskClassificationLibraryCreate, TaskClassificationLibraryUpdate
from app.crud.base import CRUDBase

# 创建 TaskClassificationLibrary 的 CRUD 对象
class CRUDTaskClassificationLibrary(CRUDBase[TaskClassificationLibrary, TaskClassificationLibraryCreate, TaskClassificationLibraryUpdate]):
    def get_unique_categories(self, db: Session) -> List[str]:
        """
        获取不重复的分类名称列表。
        """
        result = db.query(TaskClassificationLibrary.category_name).distinct().all()
        return [category[0] for category in result]

# 实例化 CRUD 对象，以便在路由（route）中使用
task_classification_library = CRUDTaskClassificationLibrary(TaskClassificationLibrary)
